#include "MoveItem.h"

MoveItem::MoveItem(QPixmap image,int width,int height)
	: QGraphicsItem()
{
	myWidth = width;
	myHeight = height;
	makePhoto(image);
}

QRectF MoveItem::boundingRect() const
{
	return QRectF(0.0f,0.0f,myWidth,myHeight);
}

void MoveItem::paint(QPainter* painter,const QStyleOptionGraphicsItem*,
						 QWidget*)
{
	painter->drawPixmap(0,0,item);
}

MoveItem::~MoveItem()
{

}

void MoveItem::makePhoto(QPixmap image)
{
	item = QPixmap(myWidth,myHeight);
	if((image.width() > myWidth - 2) || (image.height() > myHeight-2))
	image = image.scaled(myWidth-2,myHeight-2,Qt::KeepAspectRatio,Qt::SmoothTransformation);
	QPainter* painter = new QPainter(&item);
	painter->drawPixmap(static_cast<int>(myWidth*0.5f-(image.width()*0.5f)),
		static_cast<int>(myHeight*0.5f-(image.height()*0.5f)),image);
	delete painter;
}